package com.dhkj.circle.db.sqlserver;

import com.dhkj.circle.utils.DBHelper;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import static com.dhkj.circle.ui.AppContext.sLogger;

public class LSZMWXbaseSQL {
    private static LSZMWXbaseSQL lszmwXbaseSQL = new LSZMWXbaseSQL();

    public static LSZMWXbaseSQL getInstance() {
        return lszmwXbaseSQL;
    }

    public String getUserJE(String cardNo) {
        String je="0" ;
        DBHelper dbHelper = new DBHelper();
        Connection connection = dbHelper.getConnector3();
        PreparedStatement semt = null;
        ResultSet rs = null;
        try {
            semt = connection.prepareStatement("select SUM(JE)JE from LSZMWX where CARDNO=? and State=0");
            semt.setString(1, cardNo);
            semt.setQueryTimeout(10);
            rs = semt.executeQuery();
            if (rs.next()) {
                je = rs.getString("JE");
            }
        } catch (Exception e) {
            sLogger.d(e.getMessage());
        }finally {
            dbHelper.close(connection, semt, rs);
        }
        return je;
    }
    public int upJeState(String cardNo) {
        int count=0 ;
        DBHelper dbHelper = new DBHelper();
        Connection connection = dbHelper.getConnector3();
        PreparedStatement semt = null;
        ResultSet rs = null;
        try {
            semt = connection.prepareStatement("update LSZMWX set state=9 where CARDNO=? and State=0");
            semt.setString(1, cardNo);
            semt.setQueryTimeout(10);
            count = semt.executeUpdate();
        } catch (Exception e) {
            sLogger.d(e.getMessage());
        }finally {
            dbHelper.close(connection, semt, rs);
        }
        return count;
    }

}
